********************************************************************************
** 	TITLE:		us1984_anes_contact_networks                                  ** 	
**  AUTHOR:	    Philippe Mongrain                                             **
**	DATA:       NES1984                                                       **
**  DATE:	    October 2022 						                          **	
**	VERSION:	Stata 16					                                  **	
********************************************************************************

* Version control

version 16.0

* Open log file

capture log close       			  			              
log using "us1984_anes_contact_networks", replace

* Open the dataset

use "NES1984.dta", clear

* Generate variable for interview year

gen inty = 1984


**************************
** STATE-LEVEL OUTCOMES **
**************************

* Note: 1 = Republican, 2 = Democrat

gen statewinner = .

replace statewinner = 1 if V840011 == 1
replace statewinner = 1 if V840011 == 2
replace statewinner = 1 if V840011 == 4
replace statewinner = 1 if V840011 == 5
replace statewinner = 1 if V840011 == 6
replace statewinner = 1 if V840011 == 8
replace statewinner = 1 if V840011 == 9
replace statewinner = 1 if V840011 == 10
replace statewinner = 2 if V840011 == 11
replace statewinner = 1 if V840011 == 12
replace statewinner = 1 if V840011 == 13
replace statewinner = 1 if V840011 == 15
replace statewinner = 1 if V840011 == 16
replace statewinner = 1 if V840011 == 17
replace statewinner = 1 if V840011 == 18
replace statewinner = 1 if V840011 == 19
replace statewinner = 1 if V840011 == 20
replace statewinner = 1 if V840011 == 21
replace statewinner = 1 if V840011 == 22
replace statewinner = 1 if V840011 == 23
replace statewinner = 1 if V840011 == 24
replace statewinner = 1 if V840011 == 25
replace statewinner = 1 if V840011 == 26
replace statewinner = 2 if V840011 == 27
replace statewinner = 1 if V840011 == 28
replace statewinner = 1 if V840011 == 29
replace statewinner = 1 if V840011 == 30
replace statewinner = 1 if V840011 == 31
replace statewinner = 1 if V840011 == 32
replace statewinner = 1 if V840011 == 33
replace statewinner = 1 if V840011 == 34
replace statewinner = 1 if V840011 == 35
replace statewinner = 1 if V840011 == 36
replace statewinner = 1 if V840011 == 37
replace statewinner = 1 if V840011 == 38
replace statewinner = 1 if V840011 == 39
replace statewinner = 1 if V840011 == 40
replace statewinner = 1 if V840011 == 41
replace statewinner = 1 if V840011 == 42
replace statewinner = 1 if V840011 == 44
replace statewinner = 1 if V840011 == 45
replace statewinner = 1 if V840011 == 46
replace statewinner = 1 if V840011 == 47
replace statewinner = 1 if V840011 == 48
replace statewinner = 1 if V840011 == 49
replace statewinner = 1 if V840011 == 50
replace statewinner = 1 if V840011 == 51
replace statewinner = 1 if V840011 == 53
replace statewinner = 1 if V840011 == 54
replace statewinner = 1 if V840011 == 55
replace statewinner = 1 if V840011 == 56


*********************
** COMPETITIVENESS **
*********************

* Margin of victory by state (absolute difference between Democratic and Republican candidates)

gen margin = .

replace margin = 22.26171 if V840011 == 1
replace margin = 36.78621 if V840011 == 2
replace margin = 33.87884 if V840011 == 4
replace margin = 22.17624 if V840011 == 5
replace margin = 16.24916 if V840011 == 6
replace margin = 28.31926 if V840011 == 8
replace margin = 21.90197 if V840011 == 9
replace margin = 19.85057 if V840011 == 10
replace margin = 71.65528 if V840011 == 11
replace margin = 30.65833 if V840011 == 12
replace margin = 20.38699 if V840011 == 13
replace margin = 11.28374 if V840011 == 15
replace margin = 45.97246 if V840011 == 16
replace margin = 12.87804 if V840011 == 17
replace margin = 23.9916 if V840011 == 18
replace margin = 7.385033 if V840011 == 19
replace margin = 33.67417 if V840011 == 20
replace margin = 20.60569 if V840011 == 21
replace margin = 22.59832 if V840011 == 22
replace margin = 22.05303 if V840011 == 23
replace margin = 5.488663 if V840011 == 24
replace margin = 2.786999 if V840011 == 25
replace margin = 18.98995 if V840011 == 26
replace margin = .1804314 if V840011 == 27
replace margin = 24.45904 if V840011 == 28
replace margin = 20.0495 if V840011 == 29
replace margin = 22.2979 if V840011 == 30
replace margin = 41.74086 if V840011 == 31
replace margin = 34.35061 if V840011 == 32
replace margin = 37.72217 if V840011 == 33
replace margin = 20.89297 if V840011 == 34
replace margin = 20.47787 if V840011 == 35
replace margin = 5.512627 if V840011 == 36
replace margin = 24.00494 if V840011 == 37
replace margin = 31.04078 if V840011 == 38
replace margin = 18.69548 if V840011 == 39
replace margin = 37.94371 if V840011 == 40
replace margin = 12.16614 if V840011 == 41
replace margin = 7.351891 if V840011 == 42
replace margin = 3.647846 if V840011 == 44
replace margin = 27.98884 if V840011 == 45
replace margin = 26.47459 if V840011 == 46
replace margin = 16.26747 if V840011 == 47
replace margin = 27.49667 if V840011 == 48
replace margin = 49.82658 if V840011 == 49
replace margin = 17.11069 if V840011 == 50
replace margin = 25.19423 if V840011 == 51
replace margin = 13.51094 if V840011 == 53
replace margin = 10.51428 if V840011 == 54
replace margin = 9.171452 if V840011 == 55
replace margin = 42.26694 if V840011 == 56


***************************
** INDEPENDENT VARIABLES **
***************************

* Time

replace V840029 = subinstr(V840029, "-84", "",.) 
replace V840029 = subinstr(V840029, "-", "",.) 

gen sdate = "1984" + V840029

gen surveydate = date(sdate,"YMD")

format %tdMon_DD,_CCYY surveydate

gen edate = 19841106

gen electiondate=date(string(edate,"%8.0f"),"YMD")

format %tdMon_DD,_CCYY electiondate

gen time = electiondate - surveydate

* Gender

gen male = V840707

recode male (2=0)

* Age

gen age = V840429

replace age = . if age < 18

* Education

gen education = V840438

recode education (98=.)
recode education (99=.)

recode education (2=1)
recode education (3=2)
recode education (4=2)
recode education (5=3)
recode education (6=3)
recode education (7=4)
recode education (8=5)
recode education (9=6)
recode education (10=7)

* Interest for election

gen interest = V840075

recode interest (8=.)
recode interest (9=.)

replace interest = 6 - interest

replace interest = 2 if interest == 3
replace interest = 3 if interest == 5

* Caring about outcome (national)

gen care_whole = V840080

recode care_whole (8=.)
recode care_whole (9=.)

recode care_whole (3=0)

* Closeness of election (national)

gen closeness_whole = V840077

recode closeness_whole (0=.)
recode closeness_whole (8=.)
recode closeness_whole (9=.)

recode closeness_whole (1=0)
recode closeness_whole (3=1)

* Closeness of election (state)

gen closeness_state = V840079

recode closeness_state (0=.)
recode closeness_state (8=.)
recode closeness_state (9=.)

recode closeness_state (1=0)
recode closeness_state (3=1)

* Party identification scale (national)

gen pidscale = V840866

recode pidscale (8=3) // Apolitical recoded as Independent
recode pidscale (9=.) // NA recoded as missing data

replace pidscale = pidscale + 1

gen pidscale_whole = pidscale

label define pidscale 1 "Strong loser PID" 2 "Weak loser PID" 3 "Leaner loser PID" 4 "No PID" 5 "Leaner winner PID" 6 "Weak winner PID" 7 "Strong winner PID"
label values pidscale_whole pidscale

* Party identification scale (state)

gen pidscale_state = pidscale if statewinner == 1
replace pidscale_state = 8 - pidscale if statewinner == 2

label values pidscale_state pidscale

* TV news attentiveness

gen watchtv = V840110

gen tv = V840111

recode tv (0=.)
recode tv (8=.)
recode tv (9=.)

replace tv = 6 - tv

replace tv = 1 if watchtv == 0
replace tv = 1 if watchtv == 8

recode tv (.=-99)

* Press news attentiveness

gen readpress = V840112

gen press = V840116

recode press (0=.)
recode press (8=.)
recode press (9=.)

replace press = 6 - press

replace press = 1 if readpress == 0
replace press = 1 if readpress == 8

recode press (.=-99)

* Magazine news attentiveness

gen readmagazines = V840117

gen magazines = V840118

recode magazines (0=.)
recode magazines (8=.)
recode magazines (9=.)

replace magazines = 6 - magazines

replace magazines = 1 if readmagazines == 5
replace magazines = 1 if readmagazines == 8

recode magazines (.=-99)

* Radio news attentiveness

gen listenradio = V840723

gen radio = V840724

recode radio (0=.)
recode radio (8=.)
recode radio (9=.)

recode radio (7=4)

replace radio = 5 - radio // Note: 4-point scale (rather than 5-point scale)

recode radio (4=5)
recode radio (3=4)

replace radio = 1 if listenradio == 5
replace radio = 1 if listenradio == 8

recode radio (.=-99)

* News attentiveness index

egen news = rowmax(tv press magazines radio)

recode news (-99=.)

* Political discussion

gen discussion = V840107

recode discussion (8=.)
recode discussion (9=.)

replace discussion = 0 if V840105 == 5 | V840106 == 5

gen discussion_3pts = 0 if discussion < 2 & discussion!=.
replace discussion_3pts = 1 if discussion >= 2 & discussion < 4 & discussion!=.
replace discussion_3pts = 2 if discussion >= 4 & discussion!=.

* Political discussion (typical week)

gen discussion_typical = V840106

recode discussion_typical (0=.)
recode discussion_typical (8=.)
recode discussion_typical (9=.)

replace discussion_typical = 5 - discussion_typical

replace discussion_typical = 0 if V840105 == 5


*********************************
** NATIONAL-LEVEL EXPECTATIONS **
*********************************

* Forecasts (1 = Republican, 2 = Democrat, 7 = other)

gen forecast_whole = V840076

recode forecast_whole (9=.)

* Identify correct forecasts

gen correct_whole_d = 0 if forecast_whole!=1 & forecast_whole!=.
replace correct_whole_d = 1 if forecast_whole == 1


******************************
** STATE-LEVEL EXPECTATIONS **
******************************

* Forecasts (1 = Republican, 2 = Democrat, 7 = other)

gen forecast_state = V840078

recode forecast_state (9=.)

* Identify correct forecasts

gen correct_state_d = 0 if forecast_state!=statewinner & forecast_state!=.
replace correct_state_d = 1 if forecast_state == statewinner & forecast_state!=.


**********
** SAVE **
**********

save "us1984_anes.dta", replace


*******************
** MAIN ANALYSES **
*******************

* Regression analysis and percentage of correct and incorrect forecasts (national)

logistic correct_whole_d discussion pidscale_whole interest news i.care_whole i.closeness_whole age i.male education time
estimates table, star(.05 .01 .001)

tab correct_whole_d if e(sample) == 1

* Regression analysis and percentage of correct and incorrect forecasts (state)

melogit correct_state_d discussion pidscale_state interest news i.closeness_state age i.male education time margin || V840011: , or
estimates table, star(.05 .01 .001)

tab correct_state_d if e(sample) == 1


************************
** SUMMARY STATISTICS **
************************

label variable correct_whole_d "Presidency winner (DV)"
label variable correct_state_d "State winner (DV)"
label variable discussion "Discussion"
label variable pidscale_whole "National PID"
label variable pidscale_state "State PID"
label variable interest "Interest"
label variable news "News attentiveness"
label variable care_whole "Caring about outcome"
label variable closeness_whole "Perceived closeness"
label variable closeness_state "Perceived closeness"
label variable age "Age"
label variable male "Gender (male = 1)"
label variable education "Education"
label variable time "Time of interview"
label variable margin "Margin"

quietly logistic correct_whole_d discussion pidscale_whole interest news i.care_whole i.closeness_whole age i.male education time

estpost tabstat correct_whole_d discussion pidscale_whole interest news care_whole closeness_whole age male education time if e(sample) == 1, statistics(n mean p50 sd min max) columns(statistics)

esttab using "us1984_anes_summary_national.tex", substitute("\begin{table}[htbp]" "\begin{table}[H]") cells("count(label(N) fmt(%9.0fc)) mean(fmt(%5.2f) label(Mean)) p50(fmt(%5.1f) label(Median)) sd(fmt(%5.1f) label(Std. dev.)) min(fmt(%5.1f) label(Min)) max(fmt(%5.1f) label(Max))") label width(\textwidth) nomtitle nonumber noobs booktabs title("Summary statistics -- 1984 American presidential election (ANES), national level") replace

eststo clear

quietly melogit correct_state_d discussion pidscale_state interest news i.closeness_state age i.male education time margin || V840011: , or

estpost tabstat correct_state_d discussion pidscale_state interest news closeness_state age male education time if e(sample) == 1, statistics(n mean p50 sd min max) columns(statistics)

esttab using "us1984_anes_summary_state.tex", substitute("\begin{table}[htbp]" "\begin{table}[H]") cells("count(label(N) fmt(%9.0fc)) mean(fmt(%5.2f) label(Mean)) p50(fmt(%5.1f) label(Median)) sd(fmt(%5.1f) label(Std. dev.)) min(fmt(%5.1f) label(Min)) max(fmt(%5.1f) label(Max))") label width(\textwidth) nomtitle nonumber noobs booktabs title("Summary statistics -- 1984 American presidential election (ANES), state level") replace

eststo clear

log close